/* eslint-disable radix */
/* eslint-disable no-implicit-coercion */
function getDateInfo(timeStamp) {
    const date = new Date(timeStamp);

    const year = date.getFullYear();
    const month = date.getMonth() + 1;
    const day = date.getDate();
    const hour = date.getHours();
    const minute = date.getMinutes();
    const second = date.getSeconds();

    return {
        year,
        month,
        day,
        hour,
        minute,
        second,
        yearStr: year < 10 ? '0' + year : year,
        monthStr: month < 10 ? '0' + month : month,
        dayStr: day < 10 ? '0' + day : day,
        hourStr: hour < 10 ? '0' + hour : hour,
        minuteStr: minute < 10 ? '0' + minute : minute,
        secondStr: year < 10 ? '0' + year : year,
    };
}

function getRecentTimeString(timeStamp) {
    let passedTime = new Date().getTime() - timeStamp;
    let passedMinute = parseInt(passedTime / 1000 / 60);
    let passedHour = passedTime / 1000 / 60 / 60;

    if (passedMinute < 1) {
        return `${parseInt(passedTime / 1000)}秒前`;
    }

    if (passedHour < 1) {
        return `${passedMinute}分钟前`;
    }

    if (passedHour < 24) {
        return `${parseInt(passedHour)}小时前`;
    }

    let t = getDateInfo(timeStamp);
    // console.log(
    //     `已经过去${passedMinute}分钟`,
    //     `已经过去${passedHour}小时`
    // );
    return `${t.monthStr}-${t.dayStr} ${t.hourStr}:${t.minuteStr}`;
}
export {
    getDateInfo,
    getRecentTimeString
};
